package com.example.sport.service;

import com.example.sport.dao.UserDao;
import com.example.sport.pojo.QueryInfo;
import com.example.sport.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    UserDao userDao;

    public User getUser(String username) {
        return userDao.getUserByName(username);
    }

    public Map<String, Object> getUserList(QueryInfo queryInfo) {
        //获取模糊查询结果个数
        int nums = userDao.getUserCounts(queryInfo.getQuery());
        //起始页
        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        List<User> list = userDao.getAllUser(queryInfo.getQuery(), pageStart, queryInfo.getPageSize());

        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers", nums);
        res.put("data", list);
        return res;
    }

    public int updateState(int id, boolean state) {
        return userDao.updateState(id, state);
    }

    public int addUser(User user){
        return userDao.addUser(user);
    }

    public int deleteUser(int id){
        return userDao.deleteUser(id);
    }

    public User getUserById(int id){
        return userDao.getUserById(id);
    }

    public int updateUser(User user){
        return userDao.updateUser(user);
    }
}
